"激活鼠标
set mouse=a
"后面定义了相应的快捷键，可以控制其开关。搜索+num，比rnu更方便，不过在对fold进行了一些设置之后，显然rnu更加方便了。 ~/.vim/bundle/czm/ftplugin/c.vim
" set rnu

so $HOME/.vim/bundle/czm/after/python.vim
call Pattern_escape()

func! Remove_current_file()
	!rm -i %
	q
endfunc
nmap <leader>rm :call Remove_current_file()<CR>

func! s:get_visual_selection()
	" Why is this not a built-in Vim script function?!
	let [lnum1, col1] = getpos("'<")[1:2]
	let [lnum2, col2] = getpos("'>")[1:2]
	let lines = getline(lnum1, lnum2)
	let lines[-1] = lines[-1][: col2 - (&selection == 'inclusive' ? 1 : 2)]
	let lines[0] = lines[0][col1 - 1:]
	return join(lines, "\n")
endfunc

func! s:Voc_searching(word)
	exe ":38vnew | setlocal buftype=nofile bufhidden=hide noswapfile | set nonu | 0r !dict '' ".a:word
endfunc
vnoremap <silent><leader>ws <esc>:let g:word=<SID>get_visual_selection()<cr>:call <SID>Voc_searching(g:word)<cr>gg
noremap <silent><leader>ws <esc>:let g:word=expand("<cword>")<cr>:call <SID>Voc_searching(g:word)<cr>gg

highlight FindReplace_src ctermfg=green ctermbg=red guibg=#cc3388
highlight FindReplace_dest ctermfg=red ctermbg=green guibg=#33cc88
vnoremap <silent><leader>fr <esc>:let g:replace_src_str=<SID>get_visual_selection()<cr>:py vim_pattern_escape("src", "")<cr>
vnoremap <silent><leader>to <esc>:let g:replace_dest_str=<SID>get_visual_selection()<cr>:py vim_pattern_escape("dest", "2")<cr>
vnoremap <silent><leader>rp <esc>:call Find_And_Replace()<cr>:py find_and_replace()<cr>
noremap <silent><leader>rp <esc>:call Find_And_Replace()<cr>:py find_and_replace()<cr>
nnoremap <silent><leader>hc :call matchdelete(1)<cr>:call matchdelete(2)<cr>

" let s:apue_path="/test/AP-UNIX-Env/apue.3e/"
" if !(match($PWD, s:apue_path.".test") < 0)
" 	set shell=/bin/bash\ -c
" 	set makeprg=make\ %:r
" 	exe "au BufWritePost *.py,*.c,*.cpp,*.h,Makefile,*.awk silent! !rsync -aSH --exclude=*.swp --exclude=.bin ".s:apue_path.".test/ ".s:apue_path.".test.bak/"
" 	if filereadable(s:apue_path."/cscope.out")
" 		exe "cs a ".s:apue_path."/cscope.out"
" 	endif
" endif


" func! s:ToggleNERDTreeAndTagbar()
" 	if exists('t:NERDTreeBufName')
" 		let nerdtree_open = bufwinnr(t:NERDTreeBufName) != -1
" 	else
" 		let nerdtree_open = 0
" 	endif
" 	let tagbar_open = bufwinnr('__Tagbar__') != -1
" 
" 	let exit_flag = 0
" 	if nerdtree_open
" 		NERDTreeClose
" 		let exit_flag = 1
" 	endif
" 	if tagbar_open
" 		TagbarClose
" 		let exit_flag = 1
" 	endif
" 	if exit_flag
" 		return
" 	endif
" 
" 	let g:tagbar_left = 1
" 	let g:tagbar_indent = 0
" 	let g:tagbar_width = 30
" 	let g:tagbar_singleclick = 0
" 	TagbarOpen
" 
" 	" How to insure that cursor would move to the top left window? -- solved
" 	wincmd t
" 
" 	normal ggs
" 	wincmd s
" 	wincmd k
" 	NERDTree
" 	wincmd =
" 	res 10
" endfunc
" noremap <leader><leader> :call <SID>ToggleNERDTreeAndTagbar()<CR>

func! s:ToggleNERDTreeAndTagbar()
	if exists('t:NERDTreeBufName')
		let nerdtree_open = bufwinnr(t:NERDTreeBufName) != -1
	else
		let nerdtree_open = 0
	endif
	let tagbar_open = bufwinnr('__Tagbar__') != -1

	let exit_flag = 0
	if nerdtree_open
		NERDTreeClose
		let exit_flag = 1
	endif
	if tagbar_open
		TagbarClose
		let exit_flag = 1
	endif
	if exit_flag
		return
	endif

	let g:tagbar_left = 1
	let g:tagbar_indent = 0
	let g:tagbar_width = 30
	let g:tagbar_singleclick = 0
	TagbarOpen

	" How to insure that cursor would move to the top left window? -- solved
	wincmd t

	normal ggs
	wincmd s
	wincmd k
	NERDTree
	set nodiff
	wincmd =
	" res 10
endfunc
noremap <leader><leader> :call <SID>ToggleNERDTreeAndTagbar()<CR>

let s:local_path="/home/thomas/Note"
if !(match(expand("%:p"), s:local_path) < 0)
	"set syn=c
	"当文件名中包含多个_xx的时候，下面的判断方法无效。
	"matchend(expand("%:t"), "_mk") == strlen(expand("%:t")) ? set filetype = mk
	"split(expand("%:t", "_mk"), "_")[-1]
	"如果打开下面一项，则可以使用tagbar之类的插件；不过基本起不到作用
	let sfxlist=["c", "cpp", "h", "mk", "java", "sh", "xml", "html"]
	let ftlist=["c", "cpp", "cpp", "make", "java", "sh", "xml", "html"]
	let i=-1
	for sfx in sfxlist
		let i+=1
		if split(expand("%:t"), "_")[-1] == sfx
			exe "set filetype=".ftlist[i]
			break
		endif
	endfor
	"set filetype=c

	"可以用:echo getmatches()查看match的情况；用matchdelete()删除。
	call matchadd('NoteFiles', '^.*\(\.c:\|：\|\.h:\|\.cpp:\|\.java:\|\.xml:\)$', 201)
	" 	highlight NoteItems cterm=bold ctermbg=gray gui=bold guibg=gray
	" 	call matchadd('NoteItems', '^.*=>', 202)
	"call matchadd('NoteFiles', '^.*\(\.c:\|：\)$', 201)
	"match NoteFiles /^.*\(\.c:\|：\)$/
	"highlight NoteRegister ctermbg=gray guibg=gray
	"call matchadd('NoteRegister', '^.*[^\.].:$', 203)
	"2match NoteItems /^.*[^c]:$/

	if split(expand("%:t"), "_")[-1] == "ip"
		nmap <2-LeftMouse> :Utl ol<cr>
		nnoremap <cr> :Utl ol<cr>
		nnoremap <kEnter> :Utl ol<cr>
	endif

	let s:noteTagOpen=0
	let s:current_file_name=expand("%:t")
	let s:tagfile="/ram/cch/note-tag/".expand("%:t")
	"let s:dirname=system("dirname ".expand("%:p")." | tr -d '\r\n'")
	func! s:goto_Note_tag()
		let ln=line(".")
		"let pattern=system("sed -n '".ln."s!.*\\(\\/\\^.*\\)!\\1!p' ".s:dirname."/.notetag")
		let pattern=system("sed -n '".ln."s!.*\\(\\/\\^.*\\)!\\1!p' ".s:tagfile)
		wincmd l
		exe "normal ".pattern
		normal zz
	endfunc
	func! s:newNoteTagList()
		silent 32vnew __NoteTag__
		let s:note_tag_bufnr=bufnr('%')
		"setlocal buftype=nofile bufhidden=hide noswapfile
		setlocal buftype=nofile bufhidden=delete noswapfile
		setlocal nowrap
		setlocal nuw=2
		setlocal nornu
		nnoremap <buffer> <silent><2-LeftMouse> :call <SID>goto_Note_tag()<cr>
		nnoremap <buffer> <silent><cr> :call <SID>goto_Note_tag()<cr>
		nnoremap <buffer> <silent><kEnter> :call <SID>goto_Note_tag()<cr>
		setlocal syntax=tagbar
		call matchadd('NoteTag', '^[^ ].*', 202)
	endfunc
	let s:note_tag_bufnr=-1
	func! s:noteTagClose()
		if exists('t:NERDTreeBufName')
			let nerdtree_open = bufwinnr(t:NERDTreeBufName) != -1
		else
			let nerdtree_open = 0
		endif
		if s:note_tag_bufnr>=0 && buffer_exists(s:note_tag_bufnr)
			exe "bdelete ".s:note_tag_bufnr
		endif
		if nerdtree_open
			NERDTreeClose
		endif
		let s:noteTagOpen=0
	endfunc
	func! s:noteTagList()
		if (s:noteTagOpen)
			call <SID>noteTagClose()
		else
			exe "silent !note_tag ".expand("%:p").' &> /dev/null 1> '.s:tagfile
			"highlight NoteTag gui=bold guifg=#eeee11
			highlight NoteTag cterm=bold ctermfg=6 guifg=#eeee11
			" 		"exe "32vnew | setlocal buftype=nofile bufhidden=hide noswapfile | setlocal nowrap | setlocal nuw=2 | setlocal nornu | nnoremap <buffer> <2-LeftMouse> :call <SID>goto_Note_tag()<cr> | nnoremap <buffer> <cr> :call <SID>goto_Note_tag()<cr> | setlocal syntax=tagbar | call matchadd('NoteTag', '^[^ ].*', 202) | 0r !note_tag -f ".expand("%:p")
			" 		call <SID>newNoteTagList()
			" 		exe "0r !note_tag -f ".expand("%:p")
			exe ":call <SID>newNoteTagList() |  0r !note_tag -f ".expand("%:p")
			normal Gdd
			setlocal nomodifiable
			let w:autoclose=1
			normal gg
			wincmd s
			wincmd k
			NERDTree
			wincmd =
			res 10
			" Jump back to the original window
			for window in range(1, winnr('$'))
				execute window . 'wincmd w'
				if exists('w:jumpbacktohere')
					unlet w:jumpbacktohere
					break
				endif
			endfor 
			"exe "au QuitPre ".s:current_file_name." silent call <SID>noteTagClose()"
			"exe ":nnoremap <silent><leader>tp :call <SID>noteTagClose()<cr>"
			let s:noteTagOpen=1
		endif
	endfunc
	noremap <silent><leader><leader> :call <SID>noteTagList()<CR>

endif

func BitNum2ByteNum() range
	let n1=a:firstline
	let n2=a:lastline
	exe ":".n1.",".n2."s!(\\s*\\([0-9]\\+\\),)!\\='('.submatch(1).','.submatch(1)/8.')'!g"
endfunc

:filetype plugin on
:syntax on

" yellow is the same as brown
"  Replaced by ThomasChen, From:
" highlight thomas gui=bold guifg=#d00000 guibg=#d00000
"  To:
" highlight thomas gui=bold guifg=#cc3388 guibg=#cc3388
" highlight thomas gui=bold guifg=#33cc88 guibg=#33cc88
" highlight thomas gui=bold guifg=#66aabb guibg=#66aabb
"  End Replaced

let s:match_list = [[0, 'thomas'], [1, 'DarkRed'], [2, 'DarkGreen'], [3, 'DarkYellow'], [4, 'DarkBlue'], [5, 'DarkMagenta'], [6, 'DarkCyan'], [7, 'DarkGray']]
for item in s:match_list[1:]
	exe "nnoremap <silent><leader>m".item[0]." :call <SID>ThomasMatch('MarkWord".item[0]."', 0x101+".item[0].")<CR>"
	exe "vnoremap <silent><leader>m".item[0]." :call <SID>ThomasMatch('MarkWord".item[0]."', 0x101+".item[0].", <SID>get_visual_selection())<CR>"
endfor
nnoremap <leader>m0 :call <SID>ThomasMatch('thomas', 0x100)<CR>
vnoremap <leader>m0 :call <SID>ThomasMatch('thomas', 0x100, <SID>get_visual_selection())<CR>
" highlight pass gui=bold guifg=#11dd11
" nnoremap <leader>mp :call <SID>ThomasMatch('pass', 0x110)<CR>
" vnoremap <leader>mp :call <SID>ThomasMatch('pass', 0x110, <SID>get_visual_selection())<CR>




let g:match_id=0x110
"  Replaced by ThomasChen, From:
func! s:ThomasGuiMatch(group, pattern) range
	if !exists("g:match_".a:group."_list")
		exe ":let g:match_".a:group."_list=[]"
	endif
	exe ":let i=0 | for item in g:match_".a:group."_list | if \"".a:pattern."\" == item[1]"." | call matchdelete(item[0]) | call remove(g:match_".a:group."_list, i) | return | endif | let i+=1 | endfor"
"   echo "hhhhhhhhhhhhhhhhh"
" 	exe ":let g:match_".a:group."_list+=[[g:match_id, \"".a:pattern."\"]]"
	exe ":let g:match_".a:group."_list+=[[matchadd('".a:group."', '".a:pattern."', g:match_id), \"".a:pattern."\"]]"
	let g:match_id+=1
endfunc
"  To:
" func! s:ThomasGuiMatch(group, pattern) range
" 	if !exists("g:match_".a:group."_list")
" 		exe ":let g:match_".a:group."_list=[]"
" 	endif
" 	exe ":for item in g:match_".a:group."_list | if \"".a:pattern."\" == item[1]"." | call matchdelete(item[0]) | return | endif | endfor"
" " 	echo "hhhhhhhhhhhhhhhhh"
" 	exe ":let g:match_".a:group."_list+=[[g:match_id, \"".a:pattern."\"]]"
" " 	exe ":py vim.command('call matchadd(\"".a:group."\", \"".a:pattern."\", g:match_id)')"
" 	let b:matchpattern=a:pattern
" 	let b:group=a:group
" 	py vim_pattern_match("b:matchpattern", "b:group", "g:match_id")
" 	let g:match_id+=1
" endfunc
"  End Replaced



func! s:ThomasMatch(group, id, ...) range
	if a:0 > 0
		let b:matchdeleteflag=0
		if exists("g:match_".a:group)
			echo "Delete g:match_".a:group."? [y/N]:"
			let ch = getchar()
			if  ch == 121 || ch == 89
				exe ":call matchdelete(g:match_".a:group.")"
				exe ":unlet g:match_".a:group
				let b:matchdeleteflag=1
			endif
			if b:matchdeleteflag == 1
				let b:matchpattern=a:1
				let b:group=a:group
				let b:id=a:id
				py vim_pattern_match("b:matchpattern", "b:group", "b:id")
			endif
		else
			let b:matchpattern=a:1
			let b:group=a:group
			let b:id=a:id
			py vim_pattern_match("b:matchpattern", "b:group", "b:id")
		endif

	else
		if exists("g:match_".a:group)
			echo "Delete g:match_".a:group."? [y/N]:"
			let ch = getchar()
			if  ch == 121 || ch == 89
				exe ":call matchdelete(g:match_".a:group.")"
				exe ":unlet g:match_".a:group
			endif
		else
			let b:matchpattern=input('Input pattern: ')
			let b:matchpattern=b:matchpattern=='' ? expand('<cword>') : b:matchpattern
			exe ":let g:match_".a:group."=matchadd('".a:group."', '".b:matchpattern."', ".a:id.")"
		endif
	endif
endfunc
func! s:ThomasMatchList()
	let s:match_listed = []
	for item in s:match_list
		if exists("g:match_".item[1])
			let s:match_listed = s:match_listed + item
		endif
	endfor
	echo s:match_listed
endfunc
nnoremap <leader>ml :call <SID>ThomasMatchList()<CR>
"  " input 后面接<CR>将导致input失效。
" nnoremap <leader>m0 :let g:matchpattern=input('Input pattern: ')<CR>:let g:matchpattern=(g:matchpattern=="" ? expand("<cword>") : g:matchpattern)<CR>:call matchadd('thomas', g:matchpattern, 300)<CR>

" func! s:ResetFoldLevel()
" 	let c=getchar()
" 	while c != char2nr("\e") && c != char2nr("\r")
" 		if c == char2nr('a') || c == char2nr('+')
" 			let n=&foldlevel+1
" 			exe ":set foldlevel=".n
" 			redraw
" 		elseif c == char2nr('x') || c == char2nr('-')
" 			let n=&foldlevel-1
" 			exe ":set foldlevel=".n
" 			redraw
" 		elseif c == char2nr('0') || c == char2nr('.')
" 			set foldlevel=1
" 			redraw
" 		else
" 			exe "normal ".nr2char(c)
" 			redraw
" 		endif
" 		let c=getchar()
" 	endwhile
" endfunc
" nmap <silent><leader>fl :call <SID>ResetFoldLevel()<cr>
" vim 中的n_zm和n_zr可以实现foldlever的减和加。

" noremap <silent><leader>fo :foldopen<cr>
" noremap <silent><leader>fc :foldclose<cr>
" vim 中的n_za可以实现fold的打开和关闭。

func! s:FoldTitleSync()
	" exe 'normal f/yT:'
	" "exe "normal / ed: \n"
	" " 	call search(" ed: ", "w")
	" normal ]z
	" exe 'normal f:lvf*p`t'
	exe 'normal ^f vt{y'
	"exe "normal / }}}\n"
	" 	call search(" ed: ", "w")
	normal ]z4la 
	normal v$F p
endfunc

" set foldmethod=marker
" set foldmarker={{{,}}}
" set foldlevel=1

func! s:CreateNewFold(...) range
	normal mt
	if a:0 == 0 || a:1 == ''
		if getline('.') =~ " st: "
			call <SID>FoldTitleSync()
			return
		endif
	else
		if getline('.') =~ " st: "
			exe 'normal ^f:llvt*s'.join(a:000, ' ').' '
			call <SID>FoldTitleSync()
			return
		endif
		let n1=a:firstline
		let n2=a:lastline
		if n1 == n2
			" let n1=search(" st: ", "bw")
			normal [z
			let n1=line('.')
			exe 'normal ^f:llvt*s'.join(a:000, ' ').' '
			call <SID>FoldTitleSync()
			return
		endif
		exe "normal ".n2."ggo"
		exe "normal ".n1."ggO"
		let n2=n2+2
		exe ":".n1.",".n2."fold"
		exe "normal f:li ".join(a:000, ' ')
		call <SID>FoldTitleSync()
	endif
endfunc
" func! s:CreateNewFold(...) range
	" mark t
	" if a:0 == 0 || a:1 == ''
		" if getline('.') =~ "{{{"
			" call <SID>FoldTitleSync()
			" return
		" endif
	" else
		" if getline('.') =~ "{{{"
			" exe 'normal ^f vt{s '.join(a:000, ' ').' '
			" call <SID>FoldTitleSync()
			" return
		" endif
		" let n1=a:firstline
		" let n2=a:lastline
		" if n1 == n2
			" normal [z
			" let n1=line('.')
			" exe 'normal ^f vt{s '.join(a:000, ' ').' '
			" call <SID>FoldTitleSync()
			" return
		" endif
		" exe "normal ".n2."ggo"
		" exe "normal ".n1."ggO"
		" let n2=n2+2
		" exe ":".n1.",".n2."fold"
		" exe "normal ^f{i ".join(a:000, ' ').' '
		" normal [z
		" call <SID>FoldTitleSync()
	" endif
" endfunc

"com! -range -nargs=* Cf <line1>,<line2>call <SID>CreateNewFold(<f-args>)
noremap <silent><leader>fe :call <SID>CreateNewFold(input('Input comment title: '))<cr>
"nnoremap <leader>fe :call CreateNewFold(input('Input comment title: '))<cr>
"vnoremap <leader>fe :call CreateNewFold(input('Input comment title: '))<cr>

" let g:Czm_CursorLineDownFlag=0
" let g:Czm_CursorLineUpFlag=0
" func! CursorMove(key)
" 	echo "a:key=".a:key
" 	if a:key == 'j'
" 		let g:Czm_CursorLineDownFlag+=1
" 		echo "g:Czm_CursorLineDownFlag=".g:Czm_CursorLineDownFlag
" 		if g:Czm_CursorLineDownFlag == 2
" 			exe "normal ++".nr2char(5)
" 			let g:Czm_CursorLineDownFlag=0
" 		else
" 			exe "normal +"
" 		endif
" 	endif
" 	if a:key == 'k'
" 		let g:Czm_CursorLineUpFlag+=1
" 		echo "g:Czm_CursorLineUpFlag=".g:Czm_CursorLineUpFlag
" 		if g:Czm_CursorLineUpFlag == 2
" 			exe "normal --".nr2char(25)
" 			let g:Czm_CursorLineUpFlag=0
" 		else
" 			exe "normal -"
" 		endif
" 	endif
" endfunc
" nnoremap <silent>k :silent call CursorMove('k')<cr>
" nnoremap <silent>j :silent call CursorMove('j')<cr>

let g:columndisplay=1
func! s:ColumnDisplay()
	if g:columndisplay == 1
		setlocal nowrap
		setlocal nornu
		setlocal nonu
		setlocal fdc=0
		let g:columndisplay=0
	else
		setlocal wrap
		setlocal rnu
		setlocal nu
		" setlocal fdc=2
		let g:columndisplay=1
	endif
endfunction
nnoremap <leader>cd :call <SID>ColumnDisplay()<cr>

func! s:CursorLineJump(direction)
	if a:direction=="up"
		let s:jump_lines=winheight(0)/4-winline()
		if s:jump_lines < 0
			let s:jump_lines=0-s:jump_lines
			exe "normal ".s:jump_lines."-"
		else
			exe "normal ".s:jump_lines."+"
		endif
	endif
	if a:direction=="down"
		let s:jump_lines=winheight(0)*3/4-winline()
		if s:jump_lines < 0
			let s:jump_lines=0-s:jump_lines
			exe "normal ".s:jump_lines."-"
		else
			exe "normal ".s:jump_lines."+"
		endif
	endif

endfunc

"nnoremap <leader>j4 :<cr>M:exe "normal ".jump_lines."j"<cr>:unlet jump_lines<cr>
nnoremap <space>gh :call <SID>CursorLineJump("up")<cr>
nnoremap <space>gl :call <SID>CursorLineJump("down")<cr>

" nnoremap zl Lzz
" nnoremap zh Hzz
nnoremap zgl :call <SID>CursorLineJump("down")<cr>zz
nnoremap zgh :call <SID>CursorLineJump("up")<cr>zz
" nnoremap gg ggzz
" nnoremap G Gzz
" 类似的有：ctrl+u,ctrl+d,ctrl+f,ctrl+b

" nnoremap <leader>ft :Ag " st: " %<CR>


fun! ShowFuncName()
	let lnum = line(".")
	let col = col(".")
	echohl ModeMsg
	"    Replaced by ThomasChen, From:
	"   let name = getline(search("^[^ \t#/]\\{2}.*[^:]\s*$", 'bW'))
	"    To:
	let name = getline(search("^[^ \t#/]\\{2}.*[^:]\s*$", 'bnW'))
	"   echo name
	let starts = 0
	let flag = 0
	let bflag = 0
	let len = matchend(name, ")")
	let char = strpart(name, len)
	if char == ""
		let len = strlen(name)-1
		let flag += 1
	elseif char =~ " *{" || char =~ ";"
		if len < 0
			let len = matchend(name, "{") -2
" 			echo len
			let bflag = 1
		else
			let len -= 1
			let flag += 1
		endif
		" 	  echo name."~".len
	elseif len < 0
		let len = strlen(name)
	endif
	" let s:pathpattern='/u-\?boot[^/]*'
	"   echo "flag=".flag."; len=".len
	if bflag == 0
		if flag == 0
			let len += 1
		endif
		while len >= 0
			"   echo "flag=".flag."; len=".len
			let len -= 1
			let char = strpart(name, len, 1)
			if char == ')'
				let flag += 1
			endif
			if char == '('
				let flag -= 1
			endif
			if flag == 0
				let len -= 1
				break
			endif
		endwhile
		"   echo "len=".len
		while len > 0
			let char = strpart(name, len, 1)
			if char == ' ' || char == '\t'
				let len -= 1
			else
				break
			endif
		endwhile
	endif
	if len >= 0
		let starts = len
		" 	  echo "starts=".starts."; len=".len
		while starts > 0
			" 		  echo "starts=".starts."; len=".len
			if strpart(name, starts, 1) =~ ' '
				break
			endif
			let starts-= 1
		endwhile
		if starts != 0
			let starts += 1
		endif
		" 	  echo "starts=".starts."; len=".len
		let name=strpart(name, starts, len-starts+1)
	else
		let name=''
	endif
	"    End Replaced
	echohl None
" 	call search("\\%" . lnum . "l" . "\\%" . col . "c")
	"   echo "starts=".starts."; len=".len
	return name
endfun

" statusline
" cf the default statusline: %<%f\ %h%m%r%=%-14.(%l,%c%V%)\ %P
" format markers:
"   %< truncation point
"   %n buffer number
"   %f relative path to file
"   %m modified flag [+] (modified), [-] (unmodifiable) or nothing
"   %r readonly flag [RO]
"   %y filetype [ruby]
"   %= split point for left and right justification
"   %-35. width specification
"   %l current line number
"   %L number of lines in buffer
"   %c current column number
"   %V current virtual column number (-n), if different from %c
"   %P percentage through buffer
"   %) end of width specification
"  Replaced by ThomasChen, From:
" set statusline=%<\ %n:%f\ %m%r%y%{ShowFuncName()}%=%-35.(line:\ %l\ of\ %L,\ col:\ %c%V\ (%P)%)
"  To:
" set statusline=%n:%t:%{ShowFuncName()}:%{ShowBlockTitle()}\ %m%r%=T:%L,C:%c%V\ (%P)
" set statusline=%n:%t:%{ShowFuncName()}\ %m%r%=T:%L,C:%c%V\ (%P)
"  End Replaced
" set statusline=[%{ShowFuncName()}]



" set laststatus=2
" 
" " au InsertEnter * hi StatusLine term=reverse ctermfg=8 ctermbg=4 gui=undercurl guisp=Magenta
" " au InsertLeave * hi StatusLine term=reverse ctermfg=8 ctermbg=0 gui=bold,reverse
" 
" function! InsertStatuslineColor(mode)
"   if a:mode == 'i'
"     hi statusline ctermbg=red guibg=red
"   elseif a:mode == 'r'
"     hi statusline ctermbg=blue guibg=blue
"   else
"     hi statusline ctermbg=magenta guibg=magenta
"   endif
" endfunction
" 
" au InsertEnter * call InsertStatuslineColor(v:insertmode)
" au InsertChange * call InsertStatuslineColor(v:insertmode)
" au InsertLeave * hi statusline ctermbg=2 guibg=green
" " 
" " " default the statusline to green when entering Vim
" " hi statusline guibg=green



set laststatus=2
let g:smartusline_hi_replace = 'guibg=#e454ba guifg=black ctermbg=magenta ctermfg=black' 
let g:smartusline_hi_insert = 'guibg=orange guifg=black ctermbg=58 ctermfg=black' 
let g:smartusline_hi_virtual_replace = 'guibg=#e454ba guifg=black ctermbg=magenta ctermfg=black' 
let g:smartusline_hi_normal = 'guibg=#95e454 guifg=black ctermbg=lightgreen ctermfg=black' 

" func! s:Make(arg)
" " 	let s:shell_flag=&shellcmdflag
" " 	set shellcmdflag=-i
" 	exe ":make! ".a:arg
" " 	let &shellcmdflag=s:shell_flag
" " 	unlet s:shell_flag
" 	redraw!
" " 	normal 
" " 	wincmd  j
" 	if &ignorecase
" 		set hls
" 		normal /\<error\>
" 	else
" 		set ignorecase!
" 		set hls
" 		normal /\<error\>
" 		set ignorecase!
" 	endif
" endfunc
" command -bang -nargs=* Make call <SID>Make(<q-args>)
" nnoremap <silent> <Leader>jj :Make<CR><CR>:foldopen<CR>
nnoremap <leader>jj :make!<cr>:setlocal ignorecase<cr>:wincmd j<cr>/\<error\><cr><cr>



func! s:SetDiff()
	if &diff == "nodiff"
		set diff
		set scrollbind
		set cursorbind
		set scrollopt+=hor
		set nowrap
		set foldmethod=diff
		set foldcolumn=0
	else
		set nodiff
		set noscrollbind
		set nocursorbind
		set scrollopt-=hor
		set wrap
		set foldmethod&
		set foldcolumn=0
	endif
endfunc
nnoremap <silent><leader>df :call <SID>SetDiff()<cr>

func! s:ShowCursor()
	if &cursorline || &cursorcolumn
		set nocursorline
		set nocursorcolumn
	else
		set cursorline
		set cursorcolumn
	endif
endfunc
nnoremap <space>i :call <SID>ShowCursor()<cr>


if !has("gui_running")
	" Replaced by ThomasChen, From:
	colorscheme thomas
	" To:
	" colorscheme thomas_dark " range of color is not enough
	" End Replaced
endif


" func! s:Grep_matches()
	" matchadd("MarkWord5", '^[^:]\+'


